Valid = {
	validate:function($Area,modal,excludeSelector){
		var excludeSelector = excludeSelector || "";
		var modal = modal || false;
		if(modal){
			$Area = $('#pp_full_res');
		}
		var valid = true;
		var match = {};
		var messages = [];
		$Area.find('input,select,textarea').each(function(){
			var $this = $(this);
			var thisValid = true;
			var exclude = false;
			//assess exclude
			if(excludeSelector.length > 0){
				if($this.closest(excludeSelector).length > 0){
					exclude = true;
				}
			}
			
			if(!exclude){
				// check required
				if(Validate.getWords($this).indexOf("required") >= 0){
					if(!Valid.required(this.name,$Area)){
						valid = false;
						thisValid = false;
						messages.push('* '+this.title + ' is Required *');
					}
				}
				// check email
				if(Validate.getWords($this).indexOf("email") >= 0){
					if(!Valid.email(this.name,$Area)){
						valid = false;
						thisValid = false;
						messages.push('* Email Not Valid *');
					}
				}
				// get matches into struct for later
				if(Validate.getWords($this).indexOf("match") >= 0){
					var number = Validate.getWordNumber(Validate.getWords($this),"match");
					match["match"+number] = "";
				}
				
				//add or remove validation_failed class
				if(thisValid == false){
					$this.addClass('validation_failed');
				}else{
					$this.removeClass('validation_failed');
				}
			}
		});
		// check matches
		for(var key in match){
			var iterator = 0;
			var value = "";
			var value2 = "";
			var matchValid = true;
			var $matches = $Area.find('input[validate*='+key+']');
			$matches.each(function(){
				iterator++;
				var $this = $(this);
				if(iterator == 1){
					value = $this.val() || "";
				} else {
					value2 = $this.val() || "";
					if(value.toLowerCase() != value2.toLowerCase()){
						matchValid = false;
						messages.push('* '+$this.attr('title')+'s Do not match *');
					}
				}
			});
			if(!matchValid){
				valid = false;
				$matches.addClass("validation_failed");
			}
		}
		
		// show messages
		if(!valid){
			Valid.showMessages($Area,messages);
		} else {
			Valid.removeMessages($Area);
		}
		return valid;
	},
	getValue:function(name,$Area){
		var value = $Area.find('input[name='+name+'],select[name='+name+'],textarea[name='+name+']').val() || "";
		return value;
	},
	required:function(name,$Area){
		var valid = true;
		var value = Valid.getValue(name,$Area);
		if(value.length == 0){
			valid = false;
		}
		return valid;
	},
	email:function(name,$Area){
		var value = Valid.getValue(name,$Area) || "";
		var valid = _Valid._email(value);
		return valid;
	},
	match:function(name1,name2){
		var value1 = Valid.getValue(name1);
		var value2 = Valid.getValue(name2);
		return (value1 == value2);
	},
	showMessages:function($Area,messages){
		var $title = $Area.find('.validation-messages');
		var html = "";
		for(var i = 0; i < messages.length; i++){
			html += "<div class='validation-message'>" + messages[i] + "</div>";
		}
		if(messages.length > 4){ // don't show each message if more than 4 fields fail.
			html = "<div class='validation-message'>* Form Incomplete *</div>";
		}
		Valid.removeMessages($Area);
		$title.html(html);
	},
	removeMessages:function($Area){
		var $title = $Area.find('.validation-messages').html('');
	}
};